package com.feilong.edgeAI.adapter;

import static com.xuexiang.xutil.data.SPUtils.getDefaultSharedPreferences;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.aiibt.common.core.WDRecyclerAdapter;
import com.aiibt.common.util.Constant;
import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.feilong.edgeAI.R;
import com.feilong.edgeAI.databinding.HomeClassifyLayoutBindingImpl;
import com.feilong.edgeAI.model.CommadClassify;
import com.xuexiang.xutil.data.SPUtils;

import java.util.List;

public class CommadClassifyAdapter extends WDRecyclerAdapter<CommadClassify> {
    private Context context;
    public CommadClassifyAdapter(Context context, List<CommadClassify> datas) {
        this.context = context;
        addAll(datas);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.home_classify_layout;
    }

    @Override
    protected void bindView(ViewDataBinding binding, CommadClassify item, int position) {
        HomeClassifyLayoutBindingImpl b = (HomeClassifyLayoutBindingImpl) binding;
        b.title.setText(item.getTitle());
        int count = position==0?2:1;
        b.recyclerView.setLayoutManager(new GridLayoutManager(context,count));
        int space = ConvertUtils.dp2px(10);
        if(b.recyclerView.getItemDecorationCount()>0){
            RecyclerView.ItemDecoration itemDecoration = b.recyclerView.getItemDecorationAt(0);
            if(itemDecoration == null){
                b.recyclerView.addItemDecoration(new SpacingItemDecoration(space));
            }
        }else{
            b.recyclerView.addItemDecoration(new SpacingItemDecoration(space));
        }
        CommadsAdapter adapter = new CommadsAdapter(item.getCommandsList(),position);
        b.recyclerView.setAdapter(adapter);
     /*   b.bookCover.setLayoutParams(params);
        b.bookName.setText(item.getCatalog_name());
        b.bookCover.setImageURI(Uri.parse(baseUrl+item.getCatalog_image()));
        b.layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(null!=onItemClickListener){
                    onItemClickListener.onItemClick(item);
                }
            }
        });*/
    }
    static class ImageHolder extends RecyclerView.ViewHolder {

        public ImageHolder(@NonNull View view) {
            super(view);
        }
    }
    public interface OnItemClickListener<T>{
        void onItemClick(T item);
    }
    private OnItemClickListener onItemClickListener;
    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.onItemClickListener = onItemClickListener;
    }
}
